package com.xi.jetcomposedemo.activity

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.layoutId
import com.xi.jetcomposedemo.ktx.startActivity
import com.xi.jetcomposedemo.ui.compose.AppSkeleton
import com.xi.jetcomposedemo.ui.theme.JetComposeDemoTheme
import kotlinx.coroutines.delay

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            AppSkeleton(showTitleBar = false) {
                content()
            }
        }
    }

    @OptIn(ExperimentalMaterial3Api::class)
    @Composable
    private fun content() {
        LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .layoutId("lazyColumn"),
            contentPadding = PaddingValues(9.dp)
        ) {
            val textModifier = Modifier
                .background(color = Color.Green)
                .padding(4.dp, 2.dp)

            item {
                Row(
                    horizontalArrangement = Arrangement.spacedBy(9.dp),
                    modifier = Modifier.padding(top = 9.dp),
                ) {
                    Text(
                        text = "基本组件测试",
                        modifier = textModifier
                            .clickable {
                                startActivity<TestComposableActivity>()
                            }
                    )

                    Text(
                        text = "Composable状态测试",
                        modifier = textModifier
                            .clickable {
                                startActivity<TestComposeStateActivity>()
                            }
                    )
                }

            }
            item {
                Row(
                    horizontalArrangement = Arrangement.spacedBy(9.dp),
                    modifier = Modifier.padding(top = 9.dp),
                ) {
                    Text(
                        text = "测试状态恢复",
                        modifier = textModifier
                            .clickable {
                                startActivity<TestStateRecoveryActivity>()
                            }
                    )

                    Text(
                        text = "隐式传参",
                        modifier = textModifier
                            .clickable {
                                startActivity<TestCompositionLocalActivity>()
                            }
                    )

                    Text(
                        text = "手势动画",
                        modifier = textModifier
                            .clickable {
                                startActivity<TestGestureAnimationActivity>()
                            }
                    )
                }

            }
        }
    }

    @Preview(showBackground = true, showSystemUi = true)
    @Composable
    fun GreetingPreview() {
        AppSkeleton(showTitleBar = false) {
            content()
        }
    }
}